export const request = {
	baseUrl: 'http://localhost:8080', // 替换为你的实际API地址

	get(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: this.baseUrl + url,
				method: 'GET',
				data,
				header: {
					'Content-Type': 'application/json',
					'Authorization': uni.getStorageSync('token') || ''
				},
				success: (res) => {
					if (res.statusCode === 200) {
						resolve(res.data)
					} else {
						reject(res.data)
					}
				},
				fail: (err) => {
					reject(err)
				}
			})
		})
	},

	post(url, data) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: this.baseUrl + url,
				method: 'POST',
				data,
				header: {
					'Content-Type': 'application/json',
					'Authorization': uni.getStorageSync('token') || ''
				},
				success: (res) => {
					if (res.statusCode === 200) {
						resolve(res.data)
					} else {
						reject(res.data)
					}
				},
				fail: (err) => {
					reject(err)
				}
			})
		})
	}
}